<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/

if(!defined('IN_FOXPHP')) {
	exit('Data error');
}
class MobileSMS{
	
    public $Uid,$UserName,$Mobile,$Content,$UserID,$Account,$Password,$Port,$Sendcode;

	function __construct($params=array()){
		
		$this->Uid=intval($params['smsuid']);
		$this->UserName=$params['smsusername'];
		$this->Mobile=$params['smsmobile'];
		$this->Content=$params['smscontent'];
		$this->Sendcode=intval($params['smssendcode']);

		$this->Port='http://114.113.227.101:8888/';

		$this->UserID=C('mobilesmsuserid');

		$this->Account=C('mobilesmsaccount');

		$this->Password=C('mobilesmspassword');

	}

	//检查总数
	function CheckSum(){
		   
		$result=$this->CurlGetContentPOST($this->Port.'sms.aspx',array('action'=>'overage','userid'=>$this->UserID,'account'=>$this->Account,'password'=>$this->Password));

		$xml=simplexml_load_string($result);

		if($xml->returnstatus=='Sucess'){

			return array('overage'=>$xml->overage,'sendTotal'=>$xml->sendTotal);

		}else{
			
			return false;
			//exit('获取短信失败,请联系PHPAPP官方!');
		}

		
	}
	
	function SendSMS(){
		$sendcode=$this->Sendcode;
		$content=$this->Content.' '.C('mobilesign');
		if(IsNum($this->Mobile)){
			
			$result=$this->CurlGetContentPOST($this->Port.'sms.aspx',array('action'=>'send','userid'=>$this->UserID,'account'=>$this->Account,'password'=>$this->Password,'mobile'=>$this->Mobile,'content'=>$content));

			$xml=simplexml_load_string($result);

			if($xml->returnstatus=='Success'){

				if($xml->message=='ok'){

					if($this->Uid || $this->UserName){
						
						$post=array('uid'=>$this->Uid,'username'=>$this->UserName,'mobile'=>$this->Mobile,'content'=>$content,'sendcode'=>$sendcode,'datetime'=>NowTime());
	
						if (M('MobileConsume')->token(false)->create($post)){
							M('MobileConsume')->token(false)->add();
							return 'ok';
						}else{
							return false;
						}
					}

					return 'ok';

				}else{

					exit('发送短信失败!请联系网站客服!!!');
				}

			}else{

				exit('短信链接失败!请联系网站客服!!');
			}

		}else{
			exit('短信链接失败!手机号码格式有误!');
		}
		
	}
	
	function CurlGetContentPOST($url='',$data=array()){
	
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url); 
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1); 
			curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 
			$result = curl_exec($ch);
			curl_getinfo($ch);  
			curl_close($ch);
			
			return $result;
			
	}
}


?>